#pragma once
#include<iostream>
#include<unistd.h>
#include<vector>
#include <sys/wait.h>
#include <functional>
#include<time.h>
#include"Task.hpp"
#include"Processpool.hpp"

class channel
{
    public:
    channel(int fd,int pipefd)
    :_fd(fd),
    _pipefd(pipefd)
    {

    }

    void close()
    {
        ::close(_pipefd);
    }

    pid_t id()
    {
        return _fd;
    }

    int send(int n)
    {
        return ::write(_pipefd,&n,sizeof(n));
    }

    private:
    pid_t _fd;//进程标识符
    int _pipefd;//通道窗口,即标识符
};

void Work()
{
    while(true)
    {
        int num=0;
        //读取数字
        int n=::read(0,&num,sizeof(num));
        if(n==0)
        {
            std::cout<<"写端关闭,退出进程"<<std::endl;
            exit(0);
        }
        else if(n==-1)
        {
            std::cout<<"读取错误"<<std::endl;
            exit(5);
        }
    
        //正常读取
        Task task;
        task.runTask(num);
    }

}

